import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaTop, WeaTab, WeaRightMenu, WeaSearchGroup, WeaFormItem, WeaDialog, WeaLocaleProvider, WeaTools } from 'ecCom';
import { Button, message } from 'antd';
import { WeaTableNew, WeaSwitch, WeaForm } from 'comsMobx';
import { toJS } from 'mobx';

const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

import * as RD_APIS from '../../apis/receiveDoc';
import * as conditions from '../../constants/conditions';
import AdSearches from '../../public/AdSearches';
import TabButtonsAd from '../../public/TabButtonsAd';
import CreatFlowDialogComponent from './creatFlowDialogComponent';
import SetWFDia from './SetWFDia';
import ReceiveRegistDialog from './ReceiveRegistDialog';
import OdocNoRightComponent from '../common/OdocNoRightComponent';
import { affirmDeleted, validateForm } from '../../util/affirmDeleted';


@inject('receiveDoc')
@observer
class ReceiveDoc extends React.Component {
  constructor(props) {
    super(props);
    this.getSearchsAdQuick = this.getSearchsAdQuick.bind(this);
    this.getColumn = this.getColumn.bind(this);
  }

  componentDidMount() {
    const { receiveDoc, location, menuType } = this.props;
    const isReally = location.query.isReally ? location.query.isReally : false;
    const isInnerChange = location.query.isInnerChange ? location.query.isInnerChange : '0';
    receiveDoc.setMobxState({ isReally, isInnerChange });
    if (isInnerChange == '0') {
      receiveDoc.getFlowList(1);
      receiveDoc.getFlowList(2);
    }
    receiveDoc.getMenuType(menuType);
    receiveDoc.sendBackForm.initFormFields(conditions.sendBackCondt);
    receiveDoc.rejectForm.initFormFields(conditions.rejectCondt);

    RD_APIS.getWorkflowConfigCondition().then((data) => {
      receiveDoc.setStoreAttr('setWfDiaFormCon', data);
      receiveDoc.setWfDiaForm.initFormFields(receiveDoc.setWfDiaFormCon);
    });
  }

  componentWillReceiveProps(nextProps) {
    const { setMobxState, getFlowList, getMenuType, sendBackForm, rejectForm, setStoreAttr, setWfDiaForm, setWfDiaFormCon, isInnerChange,
    } = this.props.receiveDoc;
    const { location, menuType } = nextProps;
    const newIsInnerChange = location.query.isInnerChange ? location.query.isInnerChange : '0';
    if (newIsInnerChange !== isInnerChange) {
      setMobxState({
        adSearchForm: new WeaForm(),
        selectRowId: [],
        isInnerChange: newIsInnerChange,
        flowListData: [],
      });
      if (isInnerChange == '0') {
        getFlowList(1);
        getFlowList(2);
      }
      getMenuType(menuType);
      sendBackForm.initFormFields(conditions.sendBackCondt);
      rejectForm.initFormFields(conditions.rejectCondt);

      RD_APIS.getWorkflowConfigCondition().then((data) => {
        setStoreAttr('setWfDiaFormCon', data);
        setWfDiaForm.initFormFields(setWfDiaFormCon);
      });
    }
  }

  componentWillUnmount() {
    const { receiveDoc } = this.props;
    receiveDoc.setMobxState({
      adSearchForm: new WeaForm(),
      selectRowId: [],
      flowListData: [],
    });
  }

  render() {
    const { receiveDoc } = this.props;
    const { adSearchForm, loading, ifShowSearchAd, viewcondition, tableStore, sendBack, CHANGE_MODE,
      topTab, pagetitle, sendBackForm, rejectForm, ifShowRejectForm, ifSendBackForm, menuType, onSearch, hasRight, isInnerChange,
    } = receiveDoc;
    // let getColumns = null;
    // if (menuType == 'receiptRegistration') {
    //   getColumns = this.getColumn;
    // }
    if (!hasRight) {
      return <OdocNoRightComponent ecId={`${this && this.props && this.props.ecId || ''}_OdocNoRightComponent@hw5j3n`} />;
    }
    const baseSearchValue = menuType == 'receiptRegistration' ? adSearchForm.getFormParams().title
      : isInnerChange == '0' && CHANGE_MODE == 'FTP' ? adSearchForm.getFormParams().docsubject : adSearchForm.getFormParams().documentTitle;
    return (
      <div>
        {
          rejectForm.isFormInit &&
          <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@o8fhou`}
            title={getLabel('388089', '拒收公文')}
            visible={ifShowRejectForm}
            icon={'icon-coms-official'}
            iconBgcolor={'#F14A2D'}
            onCancel={this.closeReject}
            buttons={[<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@qyqayi@ok`} type={'primary'} onClick={this.rejectBtnClick} disabled={receiveDoc.loading} > {getLabel('33703', '确认')} </Button>]}
            style={{ height: 200 }}
          >
            <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@yv209x`}
              {...conditions.rejectCondt[0]}
              items={[{
                com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@4dpwdg@reject`}
                  error={rejectForm.getError(conditions.rejectCondt[0].items[0])}
                  labelCol={`${conditions.rejectCondt[0].items[0].labelCol}`}
                  hideLabel={true}
                  tipPosition={'bottom'}
                >
                  <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@xjx7fv@reject`} fieldConfig={conditions.rejectCondt[0].items[0]} form={rejectForm} />
                </WeaFormItem>),
              }]}
            />
          </WeaDialog>
        }

        {
          sendBackForm.isFormInit &&
          <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@tpg6g7`}
            title={getLabel('388090', '退回公文')}
            visible={ifSendBackForm}
            icon={'icon-coms-official'}
            iconBgcolor={'#F14A2D'}
            style={{ height: 200 }}
            onCancel={this.closeBackOut}
            buttons={[<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@1mdgjv@sendBack`} type={'primary'} onClick={() => validateForm(sendBackForm, sendBack, () => message.warn(getLabel('508377', '有必填项没有填写')))} disabled={receiveDoc.loading}> {getLabel('33703', '确认')} </Button>]}
          >
            <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@3jev2b`}
              {...conditions.sendBackCondt[0]}
              items={[{
                com: (
                  <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@eyvi7q@sendBack`}
                    labelCol={`${conditions.sendBackCondt[0].items[0].labelCol}`}
                    error={sendBackForm.getError(conditions.sendBackCondt[0].items[0])}
                    hideLabel={true}
                    tipPosition={'bottom'}
                  >
                    <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@8lf9kc@sendBack`} fieldConfig={conditions.sendBackCondt[0].items[0]} form={sendBackForm} />
                  </WeaFormItem>
                ),
              }]}
            />
          </WeaDialog>
        }

        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@77uaqu`} datas={this.getRightMenu()} >
          <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@wwf03t`}
            title={pagetitle}
            loading={loading}
            icon={<i className="icon-coms-official" />}
            iconBgcolor={'#F14A2D'}
            buttons={this.getTopButton()}
            showDropIcon={true}
            dropMenuDatas={this.getRightMenu()}
          >
            {
              <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@bmk8ak`}
                datas={topTab}
                keyParam="viewcondition" // 主键
                countParam="groupid" // 数量
                searchType={['base', 'advanced']}
                selectedKey={viewcondition}
                showSearchAd={ifShowSearchAd}
                setShowSearchAd={this.setShowSearchAd}
                buttonsAd={TabButtonsAd(receiveDoc, 'state', false)}
                searchsAd={AdSearches(receiveDoc, () => {
                  onSearch({ behavior: 'changeTab' });
                  receiveDoc.setStoreAttr('ifShowSearchAd', false);
                })}
                onChange={this.tabChange}
                searchsBaseValue={baseSearchValue}
                onSearchChange={this.tabSearchChange}
                onSearch={this.onSearch}
              />
            }

            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@4mi7c9`}
              hasOrder={true}
              needScroll={true}
              onOperatesClick={this.onOperatesClick}
              comsWeaTableStore={tableStore}
              rowSelection={this.getRowSelection()}
            // getColumns={getColumns}
            />
          </WeaTop>
        </WeaRightMenu>

        <CreatFlowDialogComponent ecId={`${this && this.props && this.props.ecId || ''}_CreatFlowDialogComponent@dckl06`} selectRowId={receiveDoc.selectRowId} />
        <ReceiveRegistDialog ecId={`${this && this.props && this.props.ecId || ''}_ReceiveRegistDialog@4cclx1`} />
        <SetWFDia ecId={`${this && this.props && this.props.ecId || ''}_SetWFDia@j6vuqa`} getNewDatasOfTable={this.getNewDatasOfTable} />

      </div>
    );
  }

  onOperatesClick = (record, index, operate, flag) => {
    const { receiveDoc } = this.props;
    const { viewcondition, setStoreAttr, setWfDiaForm, delList, menuType, getRegistrationFormData, setMobxState, createFTPWF } = receiveDoc;
    if (menuType == 'receiveDoc') {
      receiveDoc.selectRowId = [];
      // Webservice
      if (flag == '21') {
        receiveDoc.selectRowId.push(record.id);
        receiveDoc.onSigninDoc();
        return;
      } else if (flag == '22') {
        receiveDoc.selectRowId.push(record.id);
        setMobxState({ ifShowRejectForm: true });
        return;
      } else if (flag == '23') {
        receiveDoc.selectRowId.push(record.id);
        setMobxState({ ifSendBackForm: true });
        return;
      } else if (flag == '24') {
        receiveDoc.selectRowId.push(record.id);
        setMobxState({ showCreatFlow: true });
        return;
      }
      // FTP 模式
      if (viewcondition == '1') {
        if (flag == '0') {
          receiveDoc.selectRowId.push(record.id);
          setStoreAttr('selTableIdOfcreateWF', record.id);
          setStoreAttr('createWFsn', record.sn);
          setStoreAttr('createWfid', record.workflowid);
          createFTPWF();
        } else if (flag == '1') {
          setStoreAttr('companyid', record.companyid);
          setStoreAttr('chageFlag', record.chageFlag);
          setStoreAttr('sn', record.sn);
          if (operate.href === 'javascript:doConfig();') {
            setStoreAttr('ifShowTableEdit', false);
            setStoreAttr('ifShowLoadingAnimation', false);
            setWfDiaForm.updateFields({
              version: {
                value: record.version,
              },
            }, true, true);
          }
          setStoreAttr('ifShowSetWFDia', true);
        } else if (flag == '2') {
          const params = {
            sn: record.sn,
            version: record.version,
            chageFlag: record.chageFlag,
            companyid: record.companyid,
            workflowid: record.workflowid,
          };
          setStoreAttr('sn', record.sn);
          setStoreAttr('version', record.version);
          setStoreAttr('chageFlag', record.chageFlag);
          setStoreAttr('companyid', record.companyid);
          setStoreAttr('workflowid', record.workflowid);
          setStoreAttr('ifShowTableEdit', false);
          setStoreAttr('ifShowLoadingAnimation', false);
          RD_APIS.getWorkflowConfig(params).then((data) => {
            setStoreAttr('ifShowTableEdit', true);
            setStoreAttr('tableEditCols', data.columns);
            setStoreAttr('tableEditDatas', data.datas);
            setStoreAttr('tableEditTitle', data.title);
            receiveDoc.setStoreAttr('setWfDiaFormCon', data.condition);
            receiveDoc.setWfDiaForm.initFormFields(receiveDoc.setWfDiaFormCon);

            setStoreAttr('ifShowSetWFDia', true);
          });
        }
      } else if (viewcondition == '0') {
        receiveDoc.selectRowId.push(record.id);
        if (flag == '0') {
          receiveDoc.onSigninDoc();
        } else if (flag == '1') {
          setMobxState({ ifShowRejectForm: true });
        } else if (flag == '2') {
          setMobxState({ ifSendBackForm: true });
        }
      }
    } else {
      // 收文登记
      receiveDoc.type = record.receive_doc_type;
      // 收文登记
      if (flag == '0') {
        receiveDoc.selectRowId = [record.id];
        receiveDoc.document_identifier = record.document_identifier;
        getRegistrationFormData();
      } else if (flag == '1') {
        receiveDoc.isReceivecheck = true;
        receiveDoc.selectRowId = [record.id];
        getRegistrationFormData();
      } else if (flag == '2') {
        // 删除
        const params = { content: getLabel('15097', '确定要删除吗？') };
        affirmDeleted(() => delList(record.id), params);
      }
    }
  }

  getNewDatasOfTable = () => {
    // 因为wea-switch，onchange回调刚触发时，wea-form中相应字段的值还没来得及更新，所以这里加一定时间的延迟再获取wea-form中的数据
    setTimeout(() => {
      const { receiveDoc } = this.props;
      const { setWfDiaForm, setStoreAttr, chageFlag, companyid, sn } = receiveDoc;
      // 仅当工作流程表单域有值时才往后台请求接口来更新tableedit的值
      if (setWfDiaForm.getFormParams().workflowid) {
        setStoreAttr('ifShowLoadingAnimation', true);
        // 获取新的tableedit的前一瞬间，tableedit就不应该显示出来了
        setStoreAttr('ifShowTableEdit', false);
        const params = { ...setWfDiaForm.getFormParams(), chageFlag, companyid, sn };
        RD_APIS.getWorkflowConfig(params).then((data) => {
          // 后台接口走完，应当去loding，显示tableedit
          setStoreAttr('ifShowLoadingAnimation', false);
          setStoreAttr('ifShowTableEdit', true);
          setStoreAttr('tableEditCols', data.columns);
          setStoreAttr('tableEditDatas', data.datas);
          setStoreAttr('tableEditTitle', data.title);
        });
      }
    }, 30);
  }

  getSearchsAdQuick = () => {
    const { receiveDoc } = this.props;
    const arr = [];
    receiveDoc.adSearchForm.isFormInit ? (
      receiveDoc.conditioninfo.map((c, index) => {
        arr.push(
          <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@kns3dy@${index}`}
            needTigger={false}
            title={c.title}
            showGroup={c.defaultshow}
            items={c.items.map((field) => {
              if (field.domkey[0] == 'receiveDocType' || field.domkey[0] == 'registrationStatus' || field.domkey[0] == 'dealDate' || field.domkey[0] == 'communicationUnit' || field.domkey[0] == 'receiveDocDate' || field.domkey[0] == 'theme') {
                return;
              }
              return ({
                com: (
                  <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@sd53hb@${field.domkey[0]}`}
                    label={`${field.label}`}
                    labelCol={{ span: `${field.labelcol}` }}
                    wrapperCol={{ span: `${field.fieldcol}` }}
                  >
                    <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@wdagwf@${field.domkey[0]}`} fieldConfig={field} form={receiveDoc.adSearchForm} />
                  </WeaFormItem>
                ),
                col: field.conditionType.toUpperCase() == WeaTools.types.CASCADER ? 1 : 2,
              });
            })}
          />,
        );
      })
    ) : null;
    return arr;
  }

  getColumn(columns) {
    return columns.map((col) => {
      if (col.dataIndex == 'document_title') {
        return {
          ...col,
          title: col.title,
          render: (text, record) => {
            let flag = '1';
            if (record.registration_processing == '') {
              flag = '0';
            }
            return (
              <a title={record.document_title} onClick={() => this.onOperatesClick(record, '', '', flag)}>{record.document_title}</a>
            );
          },
        };
      }
      return col;
    });
  }

  openWorkflow(requestid) {
    const width = screen.availWidth - 10;
    const height = screen.availHeight - 50;
    let szFeatures = 'top=0,left=0,';
    szFeatures += `width=${width},`;
    szFeatures += `height=${height},`;
    szFeatures += 'directories=no,status=yes,toolbar=no,location=no,';
    szFeatures += 'menubar=no,scrollbars=yes,resizable=yes';
    window.open(`/workflow/request/ViewRequestForwardSPA.jsp?requestid=${requestid}`, '', szFeatures);
  }

  getRightMenu() {
    const { receiveDoc, location } = this.props;
    const { viewcondition, menuType, showRegistDialog, selectRowId, onReceive, setMobxState, onSigninDoc, customSet,
      onSearch, tableStore, delList, loading } = receiveDoc;
    let menu = [];
    const disabled = !(toJS(selectRowId).length > 0) || loading;
    const isInnerChange = location.query.isInnerChange ? location.query.isInnerChange : '0';
    if (menuType === 'receiveDoc') {
      // 外部交换
      if (viewcondition == '0') {
        menu = [
          { key: '1', icon: <i className="icon-coms-leading-in" />, content: getLabel('18526', '接收'), title: getLabel('18526', '接收'), onClick: () => onReceive() },
          { key: '2', icon: <i className="icon-coms-search" />, content: getLabel('388113', '搜索'), title: getLabel('388113', '搜索'), onClick: () => onSearch({ behavior: 'search' }) },
          { key: '3', icon: <i className="icon-coms-menu-Receive" />, disabled, content: getLabel('387687', '批量签收'), title: getLabel('387687', '批量签收'), onClick: () => onSigninDoc() },
          { key: '4', icon: <i className="icon-coms-Clear" />, disabled, content: getLabel('387688', '批量拒收'), title: getLabel('387688', '批量拒收'), onClick: () => setMobxState({ ifShowRejectForm: true }) },
          { key: '5', icon: <i className="icon-coms-go-back" />, disabled, content: getLabel('83423', '批量退回'), title: getLabel('83423', '批量退回'), onClick: () => setMobxState({ ifSendBackForm: true }) },
          { key: '6', icon: <i className="icon-coms-home" />, content: getLabel('32535', '显示列定制'), title: getLabel('32535', '显示列定制'), onClick: () => customSet() },
          { key: '7', icon: <i className="icon-coms-export" />, content: getLabel('28343', '导出Excel'), title: getLabel('28343', '导出Excel'), onClick: () => tableStore.exportAll() },
        ];
      } else if (viewcondition == '1' || viewcondition == '2' || viewcondition == '3' || viewcondition == '4') {
        menu = [
          { key: '1', icon: <i className="icon-coms-leading-in" />, content: getLabel('18526', '接收'), title: getLabel('18526', '接收'), onClick: () => onReceive() },
          { key: '2', icon: <i className="icon-coms-search" />, content: getLabel('388113', '搜索'), title: getLabel('388113', '搜索'), onClick: () => onSearch({ behavior: 'search' }) },
          { key: '6', icon: <i className="icon-coms-home" />, content: getLabel('32535', '显示列定制'), title: getLabel('32535', '显示列定制'), onClick: () => customSet() },
          { key: '7', icon: <i className="icon-coms-export" />, content: getLabel('28343', '导出Excel'), title: getLabel('28343', '导出Excel'), onClick: () => tableStore.exportAll() },
        ];
      }
      // 内部交换
      if (isInnerChange == '1') {
        menu.shift();
      }
    } else {
      // 收文登记
      menu = [
        { key: '1', icon: <i className="icon-coms-shouxie" />, content: getLabel('510164', '来文登记'), title: getLabel('510164', '来文登记'), onClick: () => showRegistDialog() },
        { key: '2', icon: <i className="icon-coms-Delete" />, content: getLabel('32136', '批量删除'), title: getLabel('32136', '批量删除'), disabled, onClick: () => affirmDeleted(() => delList(selectRowId.join(','))) },
        { key: '7', icon: <i className="icon-coms-export" />, content: getLabel('28343', '导出Excel'), title: getLabel('28343', '导出Excel'), onClick: () => tableStore.exportAll() },
      ];
    }
    return menu;
  }

  getTopButton() {
    const { receiveDoc, location } = this.props;
    const { viewcondition, menuType, setMobxState, showRegistDialog, selectRowId, delList, onSigninDoc, onReceive,loading } = receiveDoc;
    // 收文登记
    let buttons = [];
    const disabled = !(toJS(selectRowId).length > 0) || loading;
    if (menuType == 'receiptRegistration') {
      buttons = [
        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@tgbb7o@regist`} type="primary" onClick={() => showRegistDialog()}>{getLabel('510164', '来文登记')}</Button>,
        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@zytcqf@batchDelete`} type="primary" disabled={disabled} onClick={() => affirmDeleted(() => delList(selectRowId.join(',')))}>{getLabel('32136', '批量删除')}</Button>,
      ];
    } else {
      const isInnerChange = location.query.isInnerChange ? location.query.isInnerChange : '0';
      // 外部交换
      if (viewcondition == '0') {
        buttons = [
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@s9ipet@receive`} type="primary" onClick={() => onReceive()}>{getLabel('18526', '接收')}</Button>,
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@gs5483@batchSign`} type="primary" disabled={disabled} onClick={() => onSigninDoc()}>{getLabel('387687', '批量签收')}</Button>,
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9qhbru@batchReject`} type="primary" disabled={disabled} onClick={() => setMobxState({ ifShowRejectForm: true })}>{getLabel('387688', '批量拒收')}</Button>,
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@mbfrvq@batchsendBack`} type="primary" disabled={disabled} onClick={() => setMobxState({ ifSendBackForm: true })}>{getLabel('83423', '批量退回')}</Button>,
        ];
      } else if (viewcondition == '1' || viewcondition == '2' || viewcondition == '3' || viewcondition == '4') {
        buttons = [
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@l2lp9j@recive`} type="primary" onClick={() => onReceive()}>{getLabel('18526', '接收')}</Button>,
        ];
      }
      // 内部交换
      if (isInnerChange == '1') {
        buttons.shift();
      }
    }
    return buttons;
  }

  closeReject = () => {
    const { receiveDoc } = this.props;
    const { rejectFormCon, reinitWeaForm, setMobxState, tableStore, setStoreAttr } = receiveDoc;
    setStoreAttr('ifShowRejectForm', false);
    reinitWeaForm(receiveDoc, 'rejectForm', rejectFormCon);
    setMobxState({ selectRowId: [] });
    tableStore.setSelectedRowKeys([]);
  }

  closeBackOut = () => {
    const { receiveDoc } = this.props;
    const { sendBackFormCon, reinitWeaForm, setMobxState, setStoreAttr, tableStore } = receiveDoc;
    setStoreAttr('ifSendBackForm', false);
    reinitWeaForm(receiveDoc, 'sendBackForm', sendBackFormCon);
    setMobxState({ selectRowId: [] });
    tableStore.setSelectedRowKeys([]);
  }

  tabChange = (key) => {
    const { receiveDoc } = this.props;
    const { onSearch, setStoreAttr } = receiveDoc;
    receiveDoc.selectRowId = [];
    onSearch({ behavior: 'changeTab', viewcondition: key });
    setStoreAttr('ifShowSearchAd', false);
  }

  tabSearchChange = (v) => {
    const { receiveDoc } = this.props;
    const { menuType, adSearchForm, isInnerChange, CHANGE_MODE } = receiveDoc;
    if (menuType == 'receiptRegistration') {
      adSearchForm.updateFields({ title: { value: v } });
    } else if (isInnerChange == '0' && CHANGE_MODE == 'FTP') {
      adSearchForm.updateFields({ docsubject: { value: v } });
    } else {
      adSearchForm.updateFields({ documentTitle: { value: v } });
    }
  }

  rowSelectionChange = (selectedKeys, selectedRows) => {
    const { receiveDoc } = this.props;
    const { setMobxState, viewcondition, setStoreAttr } = receiveDoc;
    setMobxState({ selectRowId: selectedKeys });
    if (viewcondition == '1') {
      if (selectedRows.length > 0) {
        setStoreAttr('selTableIdOfcreateWF', selectedRows[0].id);
        setStoreAttr('createWFsn', selectedRows[0].sn);
        setStoreAttr('createWfid', selectedRows[0].workflowid);
      } else {
        setStoreAttr('selTableIdOfcreateWF', '');
        setStoreAttr('createWFsn', '');
        setStoreAttr('createWfid', '');
      }
    }
  }

  rejectBtnClick = () => {
    const { rejectForm, onReject } = this.props.receiveDoc;
    validateForm(rejectForm, onReject, () => message.warn(getLabel('508377', '有必填项没有填写')));
  }

  setShowSearchAd = (bool) => {
    this.props.receiveDoc.setStoreAttr('ifShowSearchAd', bool);
  }

  onSearch = () => this.props.receiveDoc.onSearch({ behavior: 'search' })

  getRowSelection = () => {
    const { receiveDoc } = this.props;
    return {
      onChange: this.rowSelectionChange,
      rowSelection: receiveDoc.selectRowId,
    };
  }
}

export default ReceiveDoc;
